﻿using furion.blog.Application.Contracts;
using furion.blog.Domain.Shared.Attribute;
using furion.blog.Domain.Shared.Dto.Feedback;
using furion.blog.Domain.Shared.Enum;
using furion.blog.Utils;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;

namespace furion.blog.Web.Entry.Api
{
    /// <summary>
    /// 会员操作类
    /// </summary>
    [ApiDescriptionSettings(Groups = new string[] { "FeedbackApi" })]
    [Route("api/feedback")]
    public class FeedbackApiController : IDynamicApiController
    {
        private readonly IFeedbackService _feedbackService;
        public FeedbackApiController(IFeedbackService feedbackService) {
            this._feedbackService = feedbackService;
        }

        /**********************************以下后端接口**************************************************************/

        [ActionAttribute(Name = "会员反馈分页接口", Desc = "会员反馈分页信息")]
        [HttpGet, Route("list")]
        public async Task<IActionResult> list(
            [FromQuery(Name = "page")] int pageIndex,
            [FromQuery(Name = "limit")] int pageSize,
            [FromQuery(Name = "searchContent")] string searchContent = ""
            )
        {
            var ret =await this._feedbackService.List(new Domain.Query.Feedback.FeedbackListQuery { 
               PageIndex = pageIndex,
               PageSize = pageSize,
               SearchContent = searchContent,
               IsDelete = YesOrNoEnum.No.ToString(),
            });
            return new OkObjectResult(ResultUtil.Success(ret));
        }

        [ActionAttribute(Name = "会员反馈删除接口", Desc = "删除会员反馈信息")]
        [HttpDelete, Route("{id}")]
        public async Task<IActionResult> delete(
           [FromRoute(Name = "id")] long id
           )
        {
            var ret = await this._feedbackService.Del(id);
            return new OkObjectResult(ResultUtil.Success(ret));
        }

        /**********************************以下app接口**************************************************************/

        [ActionAttribute(Name = "会员提交反馈接口", Desc = "会员提交反馈信息")]
        [HttpPost, Route("submit")]
        public async Task<IActionResult> create([FromBody]FeedbackCreateDto dto,[FromHeader(Name = "MemberId")] long memberId)
        {
            dto.MemberId = memberId;
            var ret = await this._feedbackService.Add(dto);
            return new OkObjectResult(ResultUtil.Success(ret));
        }

    }
}
